import { TableInstance } from 'element-plus';
import { Ref, ref } from 'vue';

export function useRowSelection(tableElRef: Ref<TableInstance | undefined>) {
  const selectedRowKeys = ref<string[]>([]);

  function clearSelection() {
    tableElRef.value?.clearSelection();
  }
  function getSelectionRows() {
    return tableElRef.value?.getSelectionRows();
  }
  function toggleRowSelection(row: any, selected: boolean) {
    tableElRef.value?.toggleRowSelection(row, selected);
  }
  function toggleAllSelection() {
    tableElRef.value?.toggleAllSelection();
  }

  return {
    selectedRowKeys,
    clearSelection,
    toggleRowSelection,
    toggleAllSelection,
    getSelectionRows,
  };
}
